package com.mygdx.game_objects;

import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

public class Bird {

	private int width, height;
	private Vector2 position;
	private Vector2 velocity;
	private String type;
	private float liveTime;
	private int gameWidth, gameHeight;
	private Eggs egg;
	private boolean isDropped = false;

	public Bird(String type, float x, float y, int width, int height,
			int gameWidth, int gameHeight) {
		position = new Vector2(x, y);
		int walkSpeed = 30 + (int)(Math.random() * 20); //random in range 30 - 49
		velocity = new Vector2(walkSpeed, 0);
		this.width = width;
		this.height = height;
		this.type = type;
		this.gameWidth = gameWidth;
		this.gameHeight = gameHeight;
	}

	public void update(float delta) {
		Walk(delta);
		liveTime += delta;
		if ((int) liveTime % 5 == 4 && isDropped == false) {
			Drop();
		}
		if (egg != null) {
			egg.update(delta);
			if (egg.isFallOut()) {
				egg = null;
				isDropped = false;
			}
		}
	}

	private void Walk(float delta) {
		position.add(velocity.cpy().scl(delta));
		if (position.x + width > gameWidth && velocity.x > 0) {
			velocity.x = -velocity.x;
		} else if (position.x < 0) {
			velocity.x = Math.abs(velocity.x);
		}
	}

	private void Drop() {
		egg = new Eggs(position.x + width/2, position.y + height, 15, 30, 38, gameHeight);
		isDropped = true;
	}

	public float getX() {
		return position.x;
	}

	public float getY() {
		return position.y;
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

	public String getType() {
		return type;
	}

	public Eggs getEgg() {
		return egg;
	}

	public boolean isDropped() {
		return isDropped;
	}
}
